<?php

namespace app\common\service;

use app\common\model\Dept;

class DeptService
{
    
    /**
     * 站点列表
     * @return Dept[]|array|\think\Collection|\think\db\Query[]|\think\model\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function list()
    {
        return Dept::where('parent_id', 2)->select();
    }
    
    /**
     * 排除了自己的站点
     * @return Dept[]|array|\think\Collection|\think\db\Query[]|\think\model\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function exclude($search = '')
    {
//        $deptId = UserService::getValue('dept_id');
        // ->where('id', 'not in', $deptId)
        $where = [
            ['parent_id', '=', 2],
            ['status', '=', 1]
        ];
        if (!empty($search)) {
            $where[] = ['name|leader|mobile|address', 'like', '%' . $search . '%'];
        }
        return Dept::where($where)->select()->toArray();
    }
    
    
}